package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.system.domain.vo.AppCategoryVo;
import com.ruoyi.system.domain.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FoodCategory;
import com.ruoyi.system.service.IFoodCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家的食物分类Controller
 * 
 * @author Wxl
 * @date 2022-03-16
 */
@RestController
@RequestMapping("/system/category")
public class FoodCategoryController extends BaseController
{
    @Autowired
    private IFoodCategoryService foodCategoryService;

    @GetMapping("/getCategory/{shopId}")
    public List<CategoryVo> getCategory(@PathVariable Long shopId)
    {
        List<CategoryVo> byShopId = foodCategoryService.getByShopId(shopId);
        return byShopId;
    }

    @GetMapping("/getCategoryForApp/{shopId}")
    public List<AppCategoryVo> getCategoryForApp(@PathVariable Long shopId)
    {
        List<AppCategoryVo> byShopId = foodCategoryService.getByShopIdForApp(shopId);
        return byShopId;
    }
    /**
     * 查询商家的食物分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FoodCategory foodCategory)
    {
        startPage();
        List<FoodCategory> list = foodCategoryService.selectFoodCategoryList(foodCategory);
        return getDataTable(list);
    }

    /**
     * 导出商家的食物分类列表
     */
    @Log(title = "商家的食物分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodCategory foodCategory)
    {
        List<FoodCategory> list = foodCategoryService.selectFoodCategoryList(foodCategory);
        ExcelUtil<FoodCategory> util = new ExcelUtil<FoodCategory>(FoodCategory.class);
        util.exportExcel(response, list, "商家的食物分类数据");
    }

    /**
     * 获取商家的食物分类详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(foodCategoryService.selectFoodCategoryById(id));
    }

    /**
     * 新增商家的食物分类
     */
    @Log(title = "商家的食物分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodCategory foodCategory)
    {
        return toAjax(foodCategoryService.insertFoodCategory(foodCategory));
    }

    /**
     * 修改商家的食物分类
     */
    @Log(title = "商家的食物分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodCategory foodCategory)
    {
        return toAjax(foodCategoryService.updateFoodCategory(foodCategory));
    }

    /**
     * 删除商家的食物分类
     */
    @Log(title = "商家的食物分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodCategoryService.deleteFoodCategoryByIds(ids));
    }
}
